<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: 凉城
  Date: 2021/12/21
  Time: 18:16
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>踢人页面</title>
</head>
<body>

<c:choose>
    <c:when test="${empty sessionScope.user.name}">
        <%
            request.setAttribute("msg", "用户还未登录！");
            request.getRequestDispatcher("./login.jsp").forward(request, response);
        %>

    </c:when>
    <%
        if(request.getServletContext().getAttribute("onlineUser")==null){
            request.setAttribute("msg", "您已被踢出群聊！");
            request.getRequestDispatcher("./login.jsp").forward(request, response);
        }
    %>
    <c:when test="${empty applicationScope.onlineUser}">
        <%
            request.setAttribute("msg", "您已被踢出群聊！");
            request.getRequestDispatcher("./login.jsp").forward(request, response);
        %>

    </c:when>
    <c:otherwise>
        <h1>${sessionScope.user.name}</h1>
        <a href="./login.do?action=quit">退出</a>

        <table>
            <tr>
                <th>用户名</th>
                <th>IP地址</th>
                <th>登录时间</th>
                <th>操作</th>
            </tr>
            <c:forEach var="entry" items="${applicationScope.onlineUser}">
                <tr>
                    <td>${entry.value.name}</td>
                    <td>${entry.value.ip}</td>
                    <td>${entry.value.loginTime}</td>
                    <td><a href="./login.do?action=kick&username=${entry.value.name}">踢他</a></td>
                </tr>
            </c:forEach>
        </table>


    </c:otherwise>
</c:choose>
</body>
</html>
